
#include "orangepch.h"
#include "Renderer.h"
#include "RendererCommand.h"
#include "Platform/OpenGl/OpenGLShader.h"
#include "Renderer2D.h"
namespace Orange {

	Renderer::SceneData* Renderer::m_SceneData = new Renderer::SceneData();
	
	/// <summary>
	/// ��ʼ�� ��Ⱦ��
	/// </summary>
	void Renderer::Init()
	{
		RendererCommand::Init();

		Renderer2D::Init();
	}
	void Renderer::OnWindowResize(uint32_t width, uint32_t height)
	{
		RendererCommand::SetViewport(0,0,width, height);
	}
	

	void Renderer::StartScene(OrthogonalCamera& camera)
	{
		m_SceneData->ViewPrejectMatrix = camera.GetViewPrejectMatrix();
	}

	void Renderer::EndScene()
	{
	}



	void Renderer::Submit(const Ref<Shader>& shader, const Ref<VertexArray>& vertexArray,  const glm::mat4& model)
	{
		shader->bind();
		std::dynamic_pointer_cast<OpenGLShader>(shader) ->UploadUniformMat4f("v_viewPreject", m_SceneData->ViewPrejectMatrix);
		std::dynamic_pointer_cast<OpenGLShader>(shader)->UploadUniformMat4f("v_model", model);

		vertexArray->bind();
		RendererCommand::DrawIndexs(vertexArray);
	}

}
